from flask import Flask, jsonify, request
import uuid
import json

app = Flask(__name__)

# 加载 JSON 数据库文件
def load_database(file_path):
    with open(file_path, 'r', encoding='utf-8') as f:
        return json.load(f)

transfer_requests = load_database('./DBFiles/transfer_requests_db.json')

@app.route('/request_labor', methods=['POST'])
def request_labor():
    # 因为没有实际的数据库，所以这部分代码无法编写
    # data = request.get_json()
    # user_id = data.get('user_id')
    # reason = data.get('reason')
    # transfer_id = str(uuid.uuid4())
    # transfer_requests[transfer_id] = {
    #     "user_id": user_id,
    #     "reason": reason,
    #     "status": "processing"
    # }
    # return jsonify({"transfer_id": transfer_id})
    return jsonify({"answer": "好的，正在为您转接人工"})

@app.route('/check_transfer_status', methods=['POST'])
def check_transfer_status():
    # 同样，没有数据库，这部分代码无法编写
    # transfer_id = request.args.get('transfer_id')
    # if transfer_id in transfer_requests:
    #     status = transfer_requests[transfer_id]["status"]
    #     return jsonify({"status": status})
    # else:
    #     return jsonify({"errCode": "invalid_id", "message": "提供的转人工任务ID无效"}), 200
    return jsonify({"answer": "转接人工成功"})


if __name__ == '__main__':
    app.run(debug=True, host='0.0.0.0', port=5002)